package com.hyxt.provider;

import com.hyxt.dao.RedisServiceDAO;
import com.hyxt.utils.RedisOperationUtil;

import java.util.Map;

/**
 * redis缓存接口操作实现类
 * date 2017年11月15日11:29:49
 * author  zhangcx
 */
//@Service(interfaceClass = RedisServiceDAO.class,version = "1.0.0")
public class IRedisServiceDAOImpl implements RedisServiceDAO {
    @Override
    public boolean setString(String key,String value,Integer dbIndex){
        boolean message= true;
        try {
            RedisOperationUtil.setString(key,value,dbIndex);
        }catch (Exception e){
            message = false;
        }
        return message;
    }

    @Override
    public boolean setObject(String key, Object value,Integer dbIndex) {
        boolean message= true;
        try {
            RedisOperationUtil.setObject(key,value,dbIndex);
        }catch (Exception e){
            message = false;
        }
        return message;
    }

    @Override
    public boolean setString(String key, Integer seconds, String value,Integer dbIndex) {
        boolean message= true;
        try {
            RedisOperationUtil.setString(key,seconds,value,dbIndex);
        }catch (Exception e){
            message = false;
        }
        return message;
    }

    @Override
    public boolean delete(String key,Integer dbIndex) {
        boolean message= true;
        try {
            RedisOperationUtil.deleteObject(key,dbIndex);
        }catch (Exception e){
            message = false;
        }
        return message;
    }

    @Override
    public String getString(String key,Integer dbIndex) {
        return RedisOperationUtil.getString(key,dbIndex);
    }

    @Override
    public <T> T getObject(String key, Class<T> clazz,Integer dbIndex) {
        return RedisOperationUtil.getObject(key,clazz,dbIndex);
    }

    @Override
    public void sendMessage(String channel, String message) {
        RedisOperationUtil.sendMessage(channel,message);
    }

    @Override
    public boolean setMap(String key, Map<String,String> map, Integer dbIndex) {
        try {
            RedisOperationUtil.setMap(key,map,dbIndex);
            return true;
        }catch (Exception e){
            return false;
        }
    }

    @Override
    public Map getMap(String key, Integer dbIndex) {
        try {
            return RedisOperationUtil.getMap(key,dbIndex);
        }catch (Exception e){
            return null;
        }
    }
}
